package com.ruoyi.tcustomer.service.impl;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.tcustomer.utils.MD5Util;
import com.ruoyi.websocker.MessageBean;
import com.ruoyi.websocker.mapper.TChatMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.tcustomer.mapper.TCustomerMapper;
import com.ruoyi.tcustomer.domain.TCustomer;
import com.ruoyi.tcustomer.service.ITCustomerService;

/**
 * 客服管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-08
 */
@Service
public class TCustomerServiceImpl extends BaseController implements ITCustomerService
{
    @Autowired
    private TCustomerMapper tCustomerMapper;

    @Autowired
    private TChatMessageMapper tChatMessageMapper;

    /**
     * 查询客服管理
     *
     * @param customerId 客服管理主键
     * @return 客服管理
     */
    @Override
    public TCustomer selectTCustomerByCustomerId(Long customerId)
    {
        return tCustomerMapper.selectTCustomerByCustomerId(customerId);
    }

    /**
     * 查询客服管理列表
     *
     * @param tCustomer 客服管理
     * @return 客服管理
     */
    @Override
    public List<TCustomer> selectTCustomerList(TCustomer tCustomer)
    {
        return tCustomerMapper.selectTCustomerList(tCustomer);
    }

    /**
     * 新增客服管理
     *
     * @param tCustomer 客服管理
     * @return 结果
     */
    @Override
    public AjaxResult insertTCustomer(TCustomer tCustomer)
    {

        int re=tCustomerMapper.selectCustomer(tCustomer.getCustomerAccount());
        if (re==0){
            String password=MD5Util.toMD5(tCustomer.getCustomerPassword());
            tCustomer.setCustomerPassword(password);
            return toAjax(tCustomerMapper.insertTCustomer(tCustomer));
        }else {
            return  AjaxResult.error(200,"false");
        }

    }

    /**
     * 修改客服管理
     *
     * @param tCustomer 客服管理
     * @return 结果
     */
    @Override
    public int updateTCustomer(TCustomer tCustomer)
    {
        return tCustomerMapper.updateTCustomer(tCustomer);
    }

    /**
     * 批量删除客服管理
     *
     * @param customerIds 需要删除的客服管理主键
     * @return 结果
     */
    @Override
    public int deleteTCustomerByCustomerIds(Long[] customerIds)
    {
        return tCustomerMapper.deleteTCustomerByCustomerIds(customerIds);
    }

    /**
     * 删除客服管理信息
     *
     * @param customerId 客服管理主键
     * @return 结果
     */
    @Override
    public int deleteTCustomerByCustomerId(Long customerId)
    {
        return tCustomerMapper.deleteTCustomerByCustomerId(customerId);
    }

    @Override
    public AjaxResult repeatPassword(Long id) {
        String passsword="123456";
        String password1=MD5Util.toMD5(passsword);
        int re=tCustomerMapper.repeatPassword(id,password1);
        if (re==0){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error(200,"修改失败");
        }
    }

    @Override
    public List<MessageBean> findCustomerMessageById(Long customerId,Long userId) {
        return tChatMessageMapper.findCustomerMessageById(customerId,userId);
    }
}
